home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1988 / 02 / tsrdem.c < prev   
Text File  |  1988-02-18  |  4KB  |  134 lines

  1. Code from "Converting a Turbo C Program to a TSR" by Michael J.
  2. Young, PJ, Volume 6.2.  Copyright 1987 Michael J. Young
  3.  
  4. Listing 3
  5.  
  6. #include <stdio.h>
  7. #include <process.h>
  8. #include <conio.h>
  9. #include <dos.h>
  10. #include <mem.h>
  11. #include <bios.h>
  12. #include "tsr.h"
  13.  
  14. static void Test (void);                /* The TSR demo routine.            */
  15. static void ScrSave (void);             /* Screen functions.                */
  16. static void ScrRestore (void);
  17. void ScrPutS (char *String,int Attr,int Row,int Col);
  18.  
  19. main ()
  20.      {
  21.      /* Install 'Test' as TSR function;  Ctrl-Left Shift is hotkey.         */
  22.      switch (TsrInstall (Test,CONTROL | LEFTSHIFT,(VIFP)0x11111111))
  23.           {
  24.           case WRONGDOS:
  25.                printf ("Cannot install TSR;  must have DOS version 2.0 "
  26.                        "or higher.\n");
  27.                exit (1);
  28.           case INSTALLED:
  29.                printf ("TSR already installed.\n");
  30.                exit (1);
  31.           case NOINT:
  32.                printf ("Cannot install;  no free user interrupts.\n");
  33.                exit (1);
  34.           case ERROR:                   /* General error case.              */
  35.           default:
  36.                printf ("Error installing TSR function.\n");
  37.                exit (1);
  38.           }
  39.      } /* end main */
  40.  
  41.  
  42. static void Test (void)
  43. /*
  44.      This routine is called when the hotkey is pressed.  It displays a
  45.      window and indicates whether DOS is currently active.
  46. */
  47.      {
  48.      int Row = 6;
  49.      int Col = 24;
  50.  
  51.      ScrSave ();
  52.      ScrPutS ("+-------------------------------+",0x0f,Row++,Col);
  53.      ScrPutS ("|                               |",0x0f,Row++,Col);
  54.      ScrPutS ("|        T S R   D E M O        |",0x0f,Row++,Col);
  55.      ScrPutS ("|                               |",0x0f,Row++,Col);
  56.      ScrPutS ("|   press any key to continue   |",0x0f,Row++,Col);
  57.      ScrPutS ("|                               |",0x0f,Row++,Col);
  58.      ScrPutS ("+-------------------------------+",0x0f,Row++,Col);
  59.  
  60.      if (TsrInDos ())
  61.           ScrPutS ("Now in DOS",0x0f,9,35);
  62.      else
  63.           ScrPutS ("NOT in DOS",0x0f,9,35);
  64.      bioskey (0);
  65.      ScrRestore ();
  66.  
  67.      } /* end Test */
  68.  
  69. /*** screen functions *******************************************************/
  70.  
  71. static char SaveScr [4000];
  72.  
  73. static void ScrSave (void)
  74.      {
  75. /*
  76.      This function saves the current contents of the screen in a buffer.
  77. */
  78.      int VideoSeg;
  79.  
  80.      if (*(char far *)0x00400049 == 7)       /* Test video mode.            */
  81.           VideoSeg = 0xb000;                 /* Monochrome video memory.    */
  82.      else
  83.           VideoSeg = 0xb800;                 /* Color video memory.         */
  84.      movedata (VideoSeg,0,FP_SEG ((char far *)SaveScr),
  85.                FP_OFF ((char far *)SaveScr),4000);
  86.  
  87.      } /* end ScrSave */
  88.  
  89.  
  90. static void ScrRestore (void)
  91.      {
  92. /*
  93.      This function restores the contents of a screen that was saved by ScrSave
  94. */     
  95.      int VideoSeg;
  96.  
  97.      if (*(char far *)0x00400049 == 7)       /* Test video mode.            */
  98.           VideoSeg = 0xb000;                 /* Monochrome video memory.    */
  99.      else
  100.           VideoSeg = 0xb800;                 /* Color video memory.         */
  101.      movedata (FP_SEG ((char far *)SaveScr),FP_OFF ((char far *)SaveScr),
  102.                VideoSeg,0,4000);
  103.  
  104.      } /* end ScrRestore */
  105.  
  106.  
  107. void ScrPutS (char *String,int Attr,int Row,int Col)
  108. /*
  109.      This function displays null terminated 'String' with video attribute
  110.      'Attr', beginning at the position given by 'Row' and 'Col'.
  111. */
  112.      {
  113.      register int A;                    /* Fast register storage for Attr.  */
  114.      char far *Video;                   /* Far pointer to video memory.     */
  115.      int VideoSeg,VideoOff;             /* Store video memory address.      */
  116.  
  117.      A = Attr;
  118.      if (*(char far *)0x00400049 == 7)            /* Test video mode.       */
  119.           VideoSeg = 0xb000;                      /* Monochrome segment.    */
  120.      else
  121.           VideoSeg = 0xb800;                      /* Color segment.         */
  122.  
  123.      VideoOff = Row * 160 + Col * 2;    /* Beginning video memory offset.   */
  124.      Video = MK_FP (VideoSeg,VideoOff); /* Initialize video memory pointer. */
  125.  
  126.      while (*String)          /* Write characters from string until null.   */
  127.           {
  128.           *Video++ = *String++;
  129.           *Video++ = A;
  130.           }
  131.      } /* end ScrPutS */
  132.  
  133.  
  134.